2315. 统计星号
为保证权益,题目请参考 2315. 统计星号(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
int countAsterisks(string s) {
int starCount = 0;
int startCount = 0;
for (const char ch : s) {
if (ch == '|') {
startCount = 1 - startCount;
} else if (startCount == 0 && ch == '*') {
starCount += 1;
}
}
return starCount;
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20